package com.find.answer.config;

import com.find.answer.domain.common.JacksonObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * 本来是因为老师是没有static这个目录的
 * 但是因为自己是springboot自动生成的，所以就没有用到路径映射。
 * @author Seon
 * @date 2022/10/12 22:34
 */
@Slf4j
@Configuration
public class WevMvcConfig implements WebMvcConfigurer {
    /**
     * 配置解析器
     * @param converters the list of configured converters to be extended
     */
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        converter.setObjectMapper(new JacksonObjectMapper());
        converters.add(0, converter);
    }

//    /**
//     * 还是用不到的前端资源路径映射
//     * @param registry
//     */
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/static/backend");
//        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/static/front");
//    }

//    /**
//     * 拦截器的配置，因为已经有过滤器了，所以暂时用不到。
//     * @param registry
//     */
//    public void addInterceptors(InterceptorRegistry registry) {
//        {
//            String[] backendInclude = {
//                    "/**"
//            };
//            String[] backendExclude = {
//                    "/employee/login",
//                    "/employee/logout",
//                    "/backend/**",
//                    "/front/**",
//            };
//            registry.addInterceptor(new LoginCheckInterceptor())
//                    .addPathPatterns(backendInclude)
//                    .excludePathPatterns(backendExclude);
//        }
//    }
}
